<template>
	<view>
		<utop :istype="1"></utop>
		<view class="" v-if="ishide">
			<view class="kongs" v-if="isshow">
				<view class="">
					<image src="../../static/kongs.png" mode=""></image>
					<view class="tss">
						<span v-if="orderinfo.status < 4">吸塑</span>
						<span v-else-if="orderinfo.status <= 4 || orderinfo.status < 6">圆磨</span>
						工作未结束，暂不可操作
					</view>
				</view>
			</view>
			<view class="" v-else>
				<view class="content">
					<view class="flex_bet items">
						<view class="textLeft">规格型号</view>
						<view class="rightbt">{{orderinfo.xinghao_name?orderinfo.xinghao_name:""}}
							{{orderinfo.color_name?orderinfo.color_name:''}}
						</view>
					</view>
					<view class="flex_bet items">
						<view class="textLeft">理论片数</view>
						<view class="">{{num}}</view>
					</view>
					<view class="flex_bet items">
						<view class="textLeft">制作片数</view>
						<view class="rightinput">
							<input placeholder-class="ustyle" v-model="nownum" type="number" placeholder="请输入" />
						</view>
					</view>
					<view class="bt">
						<view class="btns" @click="handleAll">
							全部报工
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popups" type="center">
			<view class="popup1">
				<!-- 第一次报工 -->
				<view class="">
					<uni-icons @click="close()" color="#979797" size="24" class="icon" type="closeempty"></uni-icons>
					<view class="img">
						<image src="../../static/info.png" mode=""></image>
					</view>
					<view class="texts">
						<view class="">
							此次报工数量：<span style="color: #196AEB;">{{nownum}}</span>
						</view>
					</view>
					<view class="context">
						是否确认<span style="color: #196AEB;">全部报工</span>已完成？
					</view>
					<view class="bnts">
						<view class="btn b1" @click="close()">
							取消
						</view>
						<view class="btn b2" @click="handleTj">
							确认提交
						</view>
					</view>
				</view>
				<!-- 多次报工 -->
			</view>
		</uni-popup>
		<uni-popup ref="popupYes" type="center" :is-mask-click="false">
			<view class="yes">
				<view class="img">
					<image src="../../static/yes.png" mode=""></image>
				</view>
				<view class="ts">
					您已提交此订单全部完成，不支持再操作
				</view>
				<view class="" style="display: flex;align-items: center;">
					<view class="btn" @click="goi">
						首页
					</view>
					<view class="btn" @click="goindex">
						扫描新订单
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getOrderInfo,
		setxipianWork
	} from '@/common/http.api.js'
	export default {
		data() {
			return {
				userInfo: uni.getStorageSync('userinfo'),
				ishide: false,
				isshow: true,
				num: '180',
				nownum: '',
				orderinfo: {},
				order_id: 0
			};
		},
		onLoad(option) {
			this.order_id = option.id
			this.getOrderInfoFun()
		},
		methods: {
			goi(){
				uni.redirectTo({
					url:'/pages/index/index'
				})
			},
			getOrderInfoFun() {
				getOrderInfo({
					order_id: this.order_id
				}).then(res => {
					this.orderinfo = res.data
					this.num = res.data.lilun_num
					this.$nextTick(() => {
						if (res.data.status == 6) {
							this.ishide = true
							this.isshow = false
						} else if (res.data.status < 6) {
							this.isshow = true
							this.ishide = true
						} else if (res.data.status >= 7) {
							this.ishide = false
							this.$refs.popupYes.open()
						}
					})

				})
			},
			goindex() {
				let that = this
				uni.scanCode({
					barCodeInput: true,
					onlyFromCamera: true,
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
							let id = res.path.substring(res.path.lastIndexOf('?') + 1, res.path.length)
								.substring(9)
							setTimeout(() => {
								that.handleSm(id)
								that.$refs.popupYes.close()
							}, 500)
						}
					},
				})
			},
			handleSm(id) {
				if (this.userInfo.type == 1) {
					uni.redirectTo({
						url: `/pages/index/xspage?id=${id}`
					})
				}
				if (this.userInfo.type == 2) {
					uni.redirectTo({
						url: `/pages/index/ympage?id=${id}`
					})
				}
				if (this.userInfo.type == 3) {
					uni.redirectTo({
						url: `/pages/index/xppage?id=${id}`
					})
				}
				if (this.userInfo.type == 4) {
					uni.redirectTo({
						url: `/pages/index/xzpage?id=${id}`
					})
				}

			},
			close() {
				this.$refs.popups.close()
			},
			handleAll() {
				if (this.nownum == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入制作片数'
					})
					return
				}
				this.$refs.popups.open()
			},
			//点击提交按钮
			handleTj() {
				
				setxipianWork({
					order_id: this.order_id,
					num: this.nownum,
				}).then(res => {
					this.ishide = false
					this.$refs.popups.close()
					this.$refs.popupYes.open()
				})

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F8FA;
	}

	.ustyle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #979797;
	}

	.kongs {
		background-color: #fff;
		width: 100%;
		display: flex;
		justify-content: center;
		height: 100vh;

		image {
			margin: 240rpx auto 100rpx;
			width: 400rpx;
			height: 324rpx;
		}

		.tss {
			font-family: PingFang SC, PingFang SC;
			font-size: 32rpx;
			color: #979797;

			span {
				font-weight: bold;
				color: #196AEB;
			}
		}
	}

	.content {
		background-color: #F7F8FA;
		padding: 20rpx;
		box-sizing: border-box;

		.bt {
			width: 710rpx;
			position: absolute;
			bottom: 40rpx;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			box-sizing: border-box;

			.btns {
				width: 670rpx;
				height: 90rpx;
				background: #196AEB;
				border-radius: 50rpx;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 90rpx;
				margin: 0 auto;
			}
		}
	}


	.items {
		width: 710rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 22rpx;
		padding: 34rpx 30rpx 34rpx 44rpx;
		box-sizing: border-box;
		margin: 0rpx auto 20rpx;

		.rightbt {
			height: 60rpx;
			background: #F2F8FF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 1rpx solid #196AEB;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #196AEB;
			line-height: 60rpx;
			text-align: center;
			padding: 0rpx 10rpx;
		}

		.rightinput {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			flex: 1;

			input {
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #196AEB;
				text-align: right;
			}
		}
	}

	.popup1 {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.icon {
			top: 28rpx;
			right: 40rpx;
			position: absolute;
		}

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
			margin: 34rpx auto 40rpx;

			span {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}

		.context {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			line-height: 35rpx;
		}

		.bnts {
			display: flex;
			margin-top: 36rpx;
			justify-content: space-between;

			.btn {
				width: 250rpx;
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 40rpx;
				line-height: 80rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
			}

			.b1 {
				border: 1rpx solid #979797;
				color: #979797;
			}

			.b2 {
				background: #196AEB;
				color: #FFFFFF;
			}
		}
	}

	.yes {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.ts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			margin-top: 20rpx;
		}

		.btn {
			height: 80rpx;
			background: #196AEB;
			border-radius: 40rpx;
			margin: 60rpx auto 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 80rpx;
			text-align: center;
			padding: 0rpx 60rpx;
		}
	}
</style>